package mt;

import java.util.Scanner;

public class q3 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        // 读取n和m
        int n = sc.nextInt();
        int m = sc.nextInt();

        // 读取每个商品的保质期
        int[] expirationDates = new int[m];
        for (int i = 0; i < m; i++) {
            expirationDates[i] = sc.nextInt();
        }

        // 读取每个商品的类型（0 表示可乐，1 表示牛马克）
        int[] productTypes = new int[m];
        for (int i = 0; i < m; i++) {
            productTypes[i] = sc.nextInt();
        }

        // 读取每个顾客的需求
        int[] li = new int[n];
        int[] ri = new int[n];
        int[] ki = new int[n];
        int[] ti = new int[n];

        for (int i = 0; i < n; i++) {
            li[i] = sc.nextInt() - 1; // 1-based index 转换为 0-based index
            ri[i] = sc.nextInt() - 1;
            ki[i] = sc.nextInt();
            ti[i] = sc.nextInt();
        }

        sc.close();  // 关闭 Scanner

        // 处理每个顾客的需求
        for (int i = 0; i < n; i++) {
            int bestProductIndex = -1;
            int maxExpirationDate = -1;
            int count = 0;

            for (int j = li[i]; j <= ri[i]; j++) {
                if (productTypes[j] == ti[i]) {
                    if (expirationDates[j] > maxExpirationDate) {
                        maxExpirationDate = expirationDates[j];
                        bestProductIndex = j;
                        count = 1;
                    } else if (expirationDates[j] == maxExpirationDate) {
                        if (count < ki[i]) {
                            bestProductIndex = j;
                            count++;
                        }
                    }
                }
            }

            if (count == ki[i]) {
                System.out.println(bestProductIndex + 1); // 输出1-based index
            } else {
                System.out.println(-1);
            }
        }
    }
}
